package com.example.siyun.controller.microcontroller;

import com.example.siyun.pojo.EnumPojo;
import com.example.siyun.pojo.Micro;
import com.example.siyun.service.microservice.MicroListService;
import com.example.siyun.util.PageResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @Auther: 全
 * @Date: 2022/9/26 09:33
 * @Description: 微圈列表的控制层
 */
@Slf4j
@RestController
public class MicroLIstController {
    @Autowired
    private MicroListService microListService;
    /**
     * 获取微圈信息
     * @return 返回微圈信息
     */
    @RequestMapping("/advanced/getmicrolist")
    public PageResult getMicroList(Micro micro, int page, int limit) {
        log.info("获取微圈信息");
        PageHelper.startPage(page, limit);
        List<Micro> list = microListService.getMicroList(micro, EnumPojo.VALUE_DEL_0);
        PageInfo<Micro> pageInfo = new PageInfo<>(list);
        PageResult pageResult=new PageResult();
        pageResult.setState(0);
        pageResult.setMessage("成功");
        pageResult.setTotal(pageInfo.getTotal());
        pageResult.setData(pageInfo.getList());
        log.info("获取微圈信息成功");
        return pageResult;
    }
    /**
     * 通过id删除微圈信息
     * @param id 要删除微圈的id
     */
    @RequestMapping("/advanced/delmicrolist")
    public PageResult delMicroList(int id){
        log.info("通过id删除微圈信息");
        Map<String, Object> map = new HashMap<>();
        microListService.delMicroList(id);
        PageResult pageResult=new PageResult();
//        pageResult.setStatus(200);
        log.info("通过id删除微圈信息成功");
        return pageResult;
    }
    /**
     * 通过id查询对应的微圈信息
     * @param id 要查询微圈的id
     * @ruturn 返回查询出来的微圈信息
     */
    @RequestMapping("/advanced/selectmicrobyid")
    public PageResult selectMicroById(int id){
        log.info("通过id查询对应的微圈信息");
        Map<String, Object> map = new HashMap<>();
        Micro micro=microListService.selectMicroById(id);
        PageResult pageResult=new PageResult();
        pageResult.setData(micro);
        log.info("通过id查询对应的微圈信息成功");
        return pageResult;
    }
}
